# _*_ coding: utf-8 _*_
# @Time : 2020/10/20 11:39
# @Author : liupengfei
# @File : tasks.py


from celery import shared_task
from .models import Activity, MemberActivity


@shared_task()
def start_activity_task(activity_id):
    # 活动由准备阶段到开始
    Activity.objects.filter(id=activity_id).update(status=Activity.BEGIN_ING)


@shared_task()
def end_activity_task(activity_id):
    # 活动由进行阶段到结束
    activity = Activity.objects.filter(id=activity_id)
    activity.update(status=Activity.FINISH)
    if activity.activity == Activity.VOTE:
        # 投票活动 定时结束任务
        MemberActivity.objects.filter(activity=activity).update(status=MemberActivity.FINISH)


@shared_task()
def end_bargain_task(member_activity_id):
    # 砍价活动  定时结束活动
    MemberActivity.objects.filter(id=member_activity_id).update(status=MemberActivity.FINISH)
